'''
本脚本实现以下功能
输入正确的账号密码
并在余额范围内取钱
存钱
账号退出
'''
import sys
#定义一些测试账户信息
a=[{"name":'z',"password":'112233',"balance":100},
   {"name":'lisi',"password":'888888',"balance":900},
   {"name":'wangwu',"password":'333333',"balance":800},
   {"name":'马六',"password":'111111',"balance":900}]

status=0


print("请输入账号")
name=input()
print("请输入密码")
password=input()

count=0
#展示界面
def display():
    global o1
    print("="*20,"请选择您接下来的操作","="*20)
    print("{0:1}{1:<13}{2:<15}".format(" ", "1.显示余额", "2.取款"))
    print("{0:1}{1:<15}{2:<15}".format(" ", "3.存款", "4.退出账户"))
    o1 = input() ##选择操作
    return o1

#显示余额
def display_balance(i,name):
    print("尊敬的用户{}，您的余额为{}".format(a[i]['name'],a[i]['balance']))

#取款
def get_money(i,name):
    print("请输入您要取的金额")
    b1 = input()
    if a[i]['balance'] < int(b1):
        print("您的余额不足,请重新输入")
        get_money(i, name)
    else:
        a[i]['balance'] = int(a[i]['balance']) - int(b1)
        print("取款金额为{}".format(b1))

#存钱
def put_money(i,name):
    print("请输入您要存入的金额")
    b1 = input()
    a[i]['balance'] = int(a[i]['balance']) + int(b1)
    print("存款金额为{}".format(b1))

#退出账户
def exist():
    print("谢谢光临,再见！")

while count<2:
    for i in range(len(a)):
        if a[i]['name']==name and a[i]['password']==password:
            display()
            while int(o1)<4:
                while o1=='1':
                    display_balance(i, name)
                    display()
                while o1=='2':
                    get_money(i, name)
                    display()
                while o1=='3':
                    put_money(i, name)
                    display()
            else:
                exist()
                sys.exit()##退出程序


    else:
       print("账号密码错误，您还可以有",2-count,"次尝试机会，请输入正确的账号密码")
       print("请输入账号")
       name = input()
       print("请输入密码")
       password = input()
       count+=1
else:
    print("账户密码输入错误次数超过3次，请联系客服！")
